package cn.com.idmy.auth.cookie;

import cn.com.idmy.auth.context.Contexts;
import cn.com.idmy.auth.login.LoginState;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;

@Setter
@Accessors(fluent = true)
@NoArgsConstructor
public class CookieManager {
    public void addCookie(@NotNull LoginState<?> state, @NotNull String name, @NotNull String value) {
        var cfg = state.config();
        Contexts.response().addCookie(new Cookie()
                .name(name)
                .value(value)
                .maxAge(cfg.tokenExp().toMillis())
                .domain(cfg.domain())
                .path(cfg.path())
                .secure(cfg.secure())
                .httpOnly(cfg.httpOnly())
                .sameSite(cfg.sameSite()));
    }
}
